<%@ page import="static com.test.ws.s1.utils.Res.fileUrl" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>路线附图管理</title>
    <!-- 复用原有样式 -->
    <style>
        /* 基础表格样式 */
        table {
            width: 100%;
            border-collapse: collapse;
            margin: 20px 0;
            box-shadow: 0 1px 3px rgba(0,0,0,0.1);
        }
        th, td {
            border: 1px solid #ddd;
            padding: 12px;
            text-align: center;
        }
        th {
            background-color: #4CAF50;
            color: white;
            font-weight: bold;
        }
        tr:nth-child(even) {
            background-color: #f2f2f2;
        }
        tr:hover {
            background-color: #e9e9e9;
        }

        /* 头像样式 */
        .avatar-circle {
            border-radius: 50%;
            width: 50px;
            height: 50px;
            object-fit: cover;
            border: 2px solid #ddd;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            transition: transform 0.3s;
        }
        .avatar-circle:hover {
            transform: scale(1.1);
        }

        /* 搜索栏样式 */
        .search-bar {
            background: #f8f9fa;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
            margin: 20px 0;
            display: flex;
            flex-wrap: wrap;
            gap: 15px;
            align-items: center;
        }
        .search-input {
            flex: 1;
            min-width: 200px;
            border: 2px solid #dee2e6;
            border-radius: 25px;
            padding: 10px 20px;
            font-size: 14px;
            transition: all 0.3s;
        }
        .search-input:focus {
            border-color: #4CAF50;
            box-shadow: 0 0 0 0.2rem rgba(76, 175, 80, 0.25);
        }
        .search-btn {
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 25px;
            padding: 10px 25px;
            cursor: pointer;
            font-weight: 500;
            transition: all 0.3s;
        }
        .search-btn:hover {
            background-color: #45a049;
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(0,0,0,0.1);
        }
        .reset-btn {
            background-color: #f44336;
            color: white;
            border: none;
            border-radius: 25px;
            padding: 10px 25px;
            cursor: pointer;
            font-weight: 500;
            transition: all 0.3s;
            text-decoration: none;
            display: inline-block;
        }
        .reset-btn:hover {
            background-color: #d32f2f;
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(0,0,0,0.1);
        }

        /* 操作按钮 */
        .action-btn {
            padding: 6px 12px;
            margin: 0 5px;
            border-radius: 4px;
            text-decoration: none;
            color: white;
            font-size: 14px;
            transition: all 0.3s;
        }
        .edit-btn {
            background-color: #2196F3;
        }
        .edit-btn:hover {
            background-color: #0b7dda;
            box-shadow: 0 2px 5px rgba(0,0,0,0.2);
        }
        .delete-btn {
            background-color: #f44336;
        }
        .delete-btn:hover {
            background-color: #d32f2f;
            box-shadow: 0 2px 5px rgba(0,0,0,0.2);
        }
        .add-btn {
            display: inline-block;
            background-color: #4CAF50;
            color: white;
            padding: 10px 20px;
            border-radius: 4px;
            text-decoration: none;
            margin-top: 20px;
            transition: all 0.3s;
        }
        .add-btn:hover {
            background-color: #45a049;
            box-shadow: 0 4px 8px rgba(0,0,0,0.1);
        }

        /* 分页样式 */
        .pagination-container {
            margin: 30px 0;
            display: flex;
            justify-content: center;
        }
        .pagination {
            display: flex;
            gap: 5px;
            list-style: none;
            padding: 0;
        }
        .page-item {
            margin: 0;
        }
        .page-link {
            padding: 8px 16px;
            border: 1px solid #ddd;
            border-radius: 4px;
            color: #4CAF50;
            text-decoration: none;
            transition: all 0.3s;
        }
        .page-item.active .page-link {
            background: #4CAF50;
            color: white;
            border-color: #4CAF50;
        }
        .page-link:hover:not(.active) {
            background: #f1f1f1;
        }
        .page-item.disabled .page-link {
            color: #ccc;
            pointer-events: none;
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            table, thead, tbody, th, td, tr {
                display: block;
            }
            thead tr {
                position: absolute;
                top: -9999px;
                left: -9999px;
            }
            tr {
                margin-bottom: 15px;
                border: 1px solid #ddd;
                border-radius: 5px;
            }
            td {
                border: none;
                border-bottom: 1px solid #eee;
                position: relative;
                padding-left: 50%;
                text-align: right;
            }
            td:before {
                content: attr(data-label);
                position: absolute;
                left: 10px;
                width: 45%;
                padding-right: 10px;
                font-weight: bold;
                text-align: left;
            }
            .search-bar {
                flex-direction: column;
                align-items: stretch;
            }
            .search-input, .search-btn, .reset-btn {
                width: 100%;
                margin-bottom: 10px;
            }
        }


        /*分页*/
        .pagination {
            display: flex;
            gap: 8px;
            padding: 15px 0;
        }

        .pagination a {
            padding: 8px 16px;
            border: 1px solid #4CAF50;
            border-radius: 4px;
            text-decoration: none;
            color: #4CAF50;
            transition: all 0.3s;
        }

        .pagination a.current {
            background: #4CAF50;
            color: white;
            border-color: #4CAF50;
        }

        .pagination a:hover:not(.current) {
            background: #f1f1f1;
        }

        /*!* 表单布局 *!*/
        /*.form-row {*/
        /*    display: flex;*/
        /*    gap: 20px;*/
        /*    margin-bottom: 15px;*/
        /*}*/

        /*.form-group {*/
        /*    flex: 1;*/
        /*}*/

        /*.form-footer {*/
        /*    text-align: right;*/
        /*    margin-top: 20px;*/
        /*}*/


        /* 网格布局调整为5列 */
        .form-row {
            display: grid;
            grid-template-columns: repeat(5, 1fr);
            gap: 12px;
            margin-bottom: 15px;
        }

        /* 下拉菜单增强样式 */
        select.form-input {
            appearance: none;
            background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%234CAF50"><path d="M7 10l5 5 5-5z"/></svg>')
            no-repeat right 12px center/12px;
            padding-right: 32px;
        }

        /* 响应式调整 */
        @media (max-width: 1200px) {
            .form-row {
                grid-template-columns: repeat(3, 1fr);
            }
        }

        @media (max-width: 992px) {
            .form-row {
                grid-template-columns: repeat(2, 1fr);
            }
        }

        @media (max-width: 768px) {
            .form-row {
                grid-template-columns: 1fr;
            }
            select.form-input {
                background-size: 10px;
                padding-right: 28px;
            }
        }

        /*111*/
        /* 修改搜索栏容器圆角 */
        .search-bar {
            border-radius: 20px;  /* 原为8px */
            overflow: hidden;     /* 新增隐藏内部元素溢出 */
        }

        /* 调整搜索按钮圆角 */
        .btn-search,
        .btn-reset {
            border-radius: 15px;  /* 原为25px */
        }

        /* 调整输入框圆角 */
        .form-input {
            border-radius: 12px;  /* 原为25px */
            padding: 12px 20px;   /* 增大内边距 */
        }

        /* 适配移动端 */
        @media (max-width: 768px) {
            .search-bar {
                border-radius: 15px;
            }

            .form-input {
                border-radius: 8px;
            }
        }


        /* 在现有样式基础上修改以下内容 */

        .btn-search,
        .btn-reset {
            /* 基础样式 */
            position: relative;
            overflow: hidden;
            transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
            font-weight: 600;
            letter-spacing: 0.8px;
            padding: 14px 32px;
            border: none;

            /* 新增样式 */
            background-image: linear-gradient(
                    135deg,
                    rgba(255,255,255,0.15) 0%,
                    transparent 50%,
                    rgba(0,0,0,0.05) 100%
            );
            box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1),
            0 2px 4px -1px rgba(0,0,0,0.06);
        }



        /* 新增附件页面专用样式 */
        .preview-card {
            position: relative;
            border-radius: 8px;
            overflow: hidden;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
            transition: transform 0.3s;
        }

        .preview-card:hover {
            transform: translateY(-3px);
        }

        .preview-img {
            width: 100%;
            height: 150px;
            object-fit: cover;
            border-bottom: 1px solid #eee;
        }

        .preview-meta {
            padding: 8px;
            background: #f8f9fa;
            display: flex;
            justify-content: space-between;
            font-size: 12px;
            color: #666;
        }

        .remove-btn {
            position: absolute;
            top: 5px;
            right: 5px;
            background: #f44336;
            color: white;
            border: none;
            border-radius: 50%;
            width: 24px;
            height: 24px;
            cursor: pointer;
            opacity: 0.9;
        }

        .remove-btn:hover {
            opacity: 1;
            transform: scale(1.1);
        }


    </style>
</head>
<body>
<h2 style="color: #4CAF50; text-align: center; margin-top: 20px;">${route.route_name} - 附图管理</h2>

<div class="search-bar" style="max-width: 1200px; margin: 20px auto;">
    <!-- 上传表单 -->
    <form action="${pageContext.request.contextPath}/imgsAdd"
          method="post" enctype="multipart/form-data">
        <input type="hidden" name="route_id" value="${param.id}">

        <!-- 文件上传行 -->
        <div class="form-row">
            <div class="form-group" style="grid-column: span 3;">
                <label>选择附图：</label>
                <input type="file" name="image" class="form-input"
                       multiple accept="image/*" onchange="previewFiles(this)">
            </div>
            <div class="form-group" style="grid-column: span 2;">
                <label>图片类型：</label>
                <select name="image_type" class="form-input" required>
                    <option value="1">详情图</option>
                    <option value="2">封面图</option>
                    <option value="3">景点图</option>
                </select>
            </div>
        </div>

        <!-- 预览区域 -->
        <div class="form-row" id="previewContainer"
             style="display: none; grid-template-columns: repeat(4, 1fr);">
            <!-- 动态生成预览图片 -->
        </div>

        <!-- 操作按钮 -->
        <div class="form-footer">
            <button type="submit" class="btn-search">上传图片</button>
            <a href="${pageContext.request.contextPath}/routeCha" class="btn-reset">返回列表</a>
        </div>
    </form>

    <!-- 已有图片展示 -->
    <div class="form-row" style="grid-template-columns: repeat(4, 1fr); gap: 20px; margin-top: 30px;">
        <c:forEach items="${attachments}" var="img">
            <div class="attachment-item">
                <img src="<%=fileUrl%>${img.file_path}"
                     class="preview-thumbnail">
                <div class="attachment-actions">
                    <a href="deleteAttachment?id=${img.id}"
                       class="action-btn delete-btn"
                       onclick="return confirm('确认删除该图片吗？')">删除</a>
                </div>
            </div>
        </c:forEach>
    </div>
</div>

<script>
    // 多图预览功能
    function previewFiles(input) {
        const container = document.getElementById('previewContainer');
        container.innerHTML = '';

        if (input.files && input.files.length > 0) {
            container.style.display = 'grid';
            Array.from(input.files).forEach(file => {
                const reader = new FileReader();
                reader.onload = function(e) {
                    const div = document.createElement('div');
                    div.innerHTML = `
                    <div style="position:relative;">
                        <img src="${e.target.result}"
                             style="width:100%; height:120px; object-fit:cover; border-radius:8px;">
                        <div style="position:absolute; bottom:5px; right:5px;">
                            <span class="action-btn delete-btn"
                                  style="padding:3px 8px;"
                                  onclick="this.parentElement.parentElement.remove()">×</span>
                        </div>
                    </div>
                `;
                    container.appendChild(div);
                }
                reader.readAsDataURL(file);
            });
        } else {
            container.style.display = 'none';
        }
    }
</script>
</body>
</html>
